#include "../mqserver/messagequeue.hpp"

#include <gtest/gtest.h>
mymq::MsgQueueManager::ptr mqmp;

class QueueTest: public testing::Environment
{
    virtual void SetUp() override
    {
        mqmp = std::make_shared<mymq::MsgQueueManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        // mqmp->clear();
        std::cout << "完成资源的清理化工作" << std::endl;
    }
};

// TEST(queue_test, insert_test)
// {
//     std::unordered_map<std::string, std::string> args = {{"k1", "v1"}};
//     mqmp->DeclareMsgQueue("queue1", true, false, false, args);
//     mqmp->DeclareMsgQueue("queue2", true, false, false, args);
//     mqmp->DeclareMsgQueue("queue3", true, false, false, std::unordered_map<std::string, std::string>());
//     mqmp->DeclareMsgQueue("queue4", true, false, false, args);
//     ASSERT_EQ(mqmp->Size(), 4);
// }

TEST(queue_test, select_test)
{
    ASSERT_EQ(mqmp->Exists("queue1"), false);
    mymq::MsgQueue::ptr mqp = mqmp->SelectMsgQueue("queue3");
    ASSERT_EQ(mqp->name, "queue3");
    ASSERT_EQ(mqp->durable, true);
    ASSERT_EQ(mqp->exclusive, false);
    ASSERT_EQ(mqp->GetArgs(), "");
}

TEST(queue_test, delete_test)
{
    mqmp->DeleteMsgQueue("queue1");
    ASSERT_EQ(mqmp->Exists("queue1"), false);
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new QueueTest);
    RUN_ALL_TESTS();

    return 0;
}